package com.etc.library.configuration;

import com.etc.library.interceptors.JWTInterceptor;
import com.etc.library.pojo.Book;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ResourcesMappingConfiguration implements WebMvcConfigurer {


    @Value("${file.real_path}")
    private String realPath;

    @Value("${file.access_all_path}")
    private String accessAllPath;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(accessAllPath).addResourceLocations("file:"+realPath);
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor()).addPathPatterns("/**").excludePathPatterns("/user/logon");
    }
}
